﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using NHibernate.Cfg.MappingSchema;

namespace MVCGen.Generators.Entity {
	public class HbmSetFieldGenerator : ICodeTypeMemberGenerator {
		private HbmSet set;
		private ICodeTypeMemberGenerator elementGenerator;

		public HbmSetFieldGenerator(HbmSet set) {
			this.set = set;
			if (set.Item1 is HbmOneToMany)
				elementGenerator = new HbmOneToManyFieldGenerator(set.name, set.Item1 as HbmOneToMany);
			else if (set.Item1 is HbmElement)
				elementGenerator = new HbmElementFieldGenerator(set.name, set.Item1 as HbmElement);
			else if (set.Item1 is HbmManyToMany)
				elementGenerator = new HbmManyToManyFieldGenerator(set.name, set.Item1 as HbmManyToMany);
			else if (set.Item1 is HbmCompositeElement)
				elementGenerator = new HbmCompositeElementFieldGenerator(set.name, set.Item1 as HbmCompositeElement);
			else if (set.Item1 is HbmManyToAny)
				elementGenerator = new HbmManyToAnyFieldGenerator(set.name, set.Item1 as HbmManyToAny);
			else
				throw new ArgumentException(String.Format("Unsupported bag item {0}", set.Item1.GetType().Name));
		}

		public CodeTypeMember Generate() {
			return elementGenerator.Generate();
		}
	}
}
